package com.googlecode.bpmcenter.dao;
 
import java.util.List;

import org.activiti.engine.RuntimeService;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.googlecode.bpmcenter.model.Partner;

@Repository
public class PartnerDAO  {
    
    @Autowired
    private SessionFactory sessionFactory;
 
    @Autowired
    private RuntimeService runtimeService;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }
 
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
 
    public void addPartner(Partner partner) {
        getSessionFactory().getCurrentSession().save(partner);
    }
 
    public void deletePartner(Partner partner) {
        getSessionFactory().getCurrentSession().delete(partner);
    }
 
    public void updatePartner(Partner partner) {
        getSessionFactory().getCurrentSession().update(partner);
    }
 
    public Partner getPartnerById(int id) {
        List list = getSessionFactory().getCurrentSession()
                                            .createQuery("from com.googlecode.bpmcenter.model.Partner where id=?")
                                            .setParameter(0, id).list();
        return (Partner)list.get(0);
    }
 
    public List<Partner> getPartners() {
        List list = getSessionFactory().getCurrentSession().createQuery("from com.googlecode.bpmcenter.model.Partner").list();
        return list;
    }

		public RuntimeService getRuntimeService() {
    	return runtimeService;
    }

		public void setRuntimeService(RuntimeService runtimeService) {
    	this.runtimeService = runtimeService;
    }
 
}